﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data;

namespace HYSoft.Web
{
    public partial class monitor_delete : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["uid"] == null || Session["uid"] == "")
            {
                Context.Response.Write("<script language=\"javascript\" type=\"text/javascript\">");
                Context.Response.Write("alert('对不起,你登录时间超时,请重新登录');top.location.href=\"index.aspx\";");
                Context.Response.Write("</script>");
                Context.Response.End();
            }
            if (Request.QueryString["Type"] != null && Request.QueryString["ID"] != null)
            {
                string Type = Request.QueryString["Type"];  //取得操作类型

                string ID = Request.QueryString["ID"];
                //  int ID = Int32.Parse(Input.checkID(Request.QueryString["ID"]));  //取得需要操作的管理员ID
                switch (Type)
                {
                    case "Del":

                        Del(ID);
                        break;
                }
            }
            data_list();

        }
        protected void data_list()
        {
            string sql = " [user_index]=" + int.Parse(Session["uid"].ToString()) + "";
            DataSet ds = new BLL.usr2monitor().GetList(sql);
            DataTable dt = ds.Tables[0];
            if (dt.Rows.Count > 0)
            {
                Repeater1.DataSource = dt;
                Repeater1.DataBind();
            }
            dt.Clear();
            dt.Dispose();
        }

        protected void Del(string ID)
        {
        //    comm_data da = new comm_data();
        //    int gid = Int32.Parse(Input.checkID(ID));

        //    da.deltable("monitor", " [index]=" + gid);
        //    da.deltable("monitor_to_user", " [monitor_index]=" + gid);
        //    da.updatatable("gprsNode", " areano=-1   where areano=" + gid);
        //    Response.Write("<script>alert('删除监测点成功！');window.location = 'gxjt.aspx';</script>");
   


            int gid = Int32.Parse(ID.ToString().Trim());
            new BLL.monitor().Delete(gid);
            string sql = " [monitor_index]="+gid+"";
            DataSet ds = new BLL.monitor_to_user().GetList(sql);
            new BLL.monitor_to_user().Delete(int.Parse(ds.Tables[0].Rows[0]["index"].ToString().Trim()));
            new BLL.gprsNode().Updateareano(gid,-1);
            //sql = " areano="+gid+"";
            //DataSet ds1 = new BLL.gprsNode().GetList(sql);
            //Model.gprsNode gprsnode = new BLL.gprsNode().GetModel(int.Parse(ds1.Tables[0].Rows[0]["index"].ToString().Trim()));
            //gprsnode.areano = -1;
            //new BLL.gprsNode().Update(gprsnode);
            Response.Write("<script>alert('删除监测点成功！');window.location = 'monitor_delete.aspx';</script>");
        }
    }
}